<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="6" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('项目所需专家抽取状态')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
<!--                @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
          <!--<a-menu-item key="2" @click="professorRandomChoose"><a-icon type="user-add" />专家抽取</a-menu-item>-->
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <!--项目状态-->
        <span slot="projectStatus" slot-scope="text,record">
          <a :class="record.projectStatus==='已完成' ? 'fontgreen' :(record.projectStatus==='抽取中' ? 'fontyellow' : 'fontred')">{{initStatus(record.projectStatus)}}</a>
        </span>

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)">编辑</a>-->

          <!--评价组件-->
          <ProjectProfessorComments :project="record"/>

          <a-divider type="vertical"/>
          <a :class='(record.projectStatus=="BEGIN")?"":(record.projectStatus=="WARN")?"choose":(record.projectStatus=="WAIT")?"":"notChoose"'
             @click="professorRandomChoose(record)">{{(record.projectStatus=="WAIT")?"等待确认":"专家抽取"}}</a>
<!--           <a-button type="link" :text='(record.projectStatus=="WAIT")?"等待确认":"专家抽取"' >-->
<!--          </a-button>-->
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
                <a-popconfirm title="确定要修改项目信息吗?" @confirm="() => handleEdit(record)">
                  <a>编辑</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <projectProfessorInfo-modal ref="modalForm" @ok="modalFormOk"></projectProfessorInfo-modal>
  </a-card>
</template>
<style>
  .choose {

    color: #ee9900;
  }

  .notChoose {

    color: #e8e8e8;
  }
  .fontgreen{
    color:green;
  }
  .fontyellow{
    color:gold;
  }
  .fontred{
    color:red;
  }
  .fontdelete{
    color: #aaa0a0;
  }
</style>
<script>

  import {deleteAction, getAction, downFile, getFileAccessHttpUrl} from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import {loadCategoryData} from '@/api/api'
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import ProjectProfessorInfoModal from './modules/ProjectProfessorInfoModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import ProjectProfessorComments from "./modules/ProjectProfessorComments";
  export default {
    name: "ProjectProfessorInfoList",
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      ProjectProfessorInfoModal,
      ProjectProfessorComments
    },
    data() {
      return {
        queryParam: {},
        description: '项目所需专家抽取状态管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '项目名称',
            align: "center",
            dataIndex: 'projectName'
          },
/*          {
            title: '项目类型',
            align: "center",
            dataIndex: 'projectType'
          },*/
          // {
          //   title:'专家人数',
          //   align:"center",
          //   dataIndex: 'professorNumber'
          // },
          // {
          //   title:'目前所需人数',
          //   align:"center",
          //   dataIndex: 'needProfessorNumber'
          // },
          {
            title: '评标时间',
            align: "center",
            dataIndex: 'professorWorkBeginTime'
          },
          {
            title: '评标地点',
            align: "center",
            dataIndex: 'professorWorkAddress'
          },
          {
            title: '项目金额',
            align: "center",
            dataIndex: 'projectAmount'
          },
          {
            title:'项目状态',
            align:"center",
            scopedSlots: { customRender: 'projectStatus' },
            // dataIndex:'project.projectStatus'
          },
          {
            title: '项目附件',
            align: "center",
            dataIndex: 'projectFile',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            // fixed:"right",
            width: 147,
            scopedSlots: {customRender: 'action'}
          }
        ],
        url: {
          list: "/projectProfessorInfo/list",
          delete: "/projectProfessorInfo/delete",
          deleteBatch: "/projectProfessorInfo/deleteBatch",
          exportXlsUrl: "/projectProfessorInfo/exportXls",
          importExcelUrl: "/projectProfessorInfo/importExcel",
          randomChoose: "/projectProfessorInfo/randomChoose",
          queryProfessorNumber: "/projectProfessorInfo/queryProfessorNumber"
        },
        dictOptions: {},
        bpmStatusDictOptions:[],
      }
    },

    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initStatus(projectStatus){
        let statusArr = ['BEGIN','RUNNING','FINISH','WARN','WAIT','OVER']
        let codeArr = ['未抽取','抽取中','已完成','专家库人数不足','待确认','已结束']
        for (let i = 0; i < statusArr.length; i++) {
          if (projectStatus === statusArr[i]){
            return codeArr[i]
          }
        }
      },
      onChange(date, dateString) {

        // 把值分别存储
        let beginDate = dateString[0]
        let overDate = dateString[1]
        // 把值放入queryParam中
        this.queryParam.beginDate = beginDate
        this.queryParam.overDate = overDate
        console.log(this.queryParam)

      },
      show(record){
        console.log(record)
      },
      initDictConfig() {
        loadCategoryData({code: 'B03'}).then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'professorType', res.result)
          }
        })
      },
      professorRandomChoose: function (record) {

        var id = record.id;

        if (record.projectStatus == "FINISH"||record.projectStatus=="RUNNING" || record.projectStatus == "OVER") {

          this.$message.warn("该项目已经抽取过专家");
        } else if(record.projectStatus == "WAIT"){
          this.$router.push({
            name: 'diy-ProjectOwnProfessorList',
            query:{
               projectId:record.id
            }
          })
          // this.$message.warn("请到抽取详情页面确认抽取的专家");
        } else{
          console.log("当前项目的状态",record.projectStatus)
          if (!this.url.queryProfessorNumber) {
            this.$message.error("请设置url.queryProfessorNumber属性!")
            return
          }
          if (!this.url.randomChoose) {
            this.$message.error("请设置url.randomChoose属性!")
            return
          }
          var ids = "";
          ids = id;
          var that = this;
          this.$confirm({
            title: "确认信息无误开始抽取专家",
            content: "是否抽取专家?",
            onOk: function () {
              that.loading = true;

              getAction(that.url.queryProfessorNumber + "/" + id).then((res) => {
                if (res.success) {
                  console.log("人数符合要求，进入抽取函数")
                  deleteAction(that.url.randomChoose, {ids: ids}).then((res) => {
                    if (res.success) {
                      console.log("进入专家人数判断");
                      console.log(res);
                      that.$message.success(res.message);
                      that.loadData();
                      that.onClearSelected();
                    } else {
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.loading = false;
                  });
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              })
            }
          });
        }
      }
    }
  }
</script>
<style scoped>
  /*@import '~@assets/less/common.less';*/

</style>